package com.until;

import javax.sound.sampled.LineUnavailableException;
import java.util.concurrent.Exchanger;

public class Testexchanger {
    public static void main(String[]args){
        final Exchanger exchanger = new Exchanger();
        //Action action=new Action();


        new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(1000);
                    exchanger.exchange(Thread.currentThread().getName()+"data");
                    System.out.println(Thread.currentThread().getName()+"我交给你了");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(new Runnable() {
            public void run() {
                try {
                    exchanger.exchange(Thread.currentThread().getName()+"data");
                    System.out.println(Thread.currentThread().getName()+"我交给你了");

                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();

    }

}

